
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/widget_extension.dart';

///特殊作业-自定义选择控件
///[title] 标题
///[onCallBack] 输入回调
///[selectText] 选中的文字显示
///[hintText] 提示文字
///[isRequired] 是否必填
///[isEnabled] 是否可编辑
///[isShowDivider] 是否显示分割线
/// demo:
/// ``` dart
/// CustomSelectPage(
///   title: '标题',
///   onCallBack:(){}
/// );
/// ```
class CustomSelectPage extends StatefulWidget {
  const CustomSelectPage({
    required this.title,
    required this.onCallBack,
    super.key,
    this.selectText = '',
    this.hintText,
    this.isRequired,
    this.isEnabled = true,
    this.isShowDivider = true,
    this.height = 50,
    this.titleFontWeight,
  });

  final String title;
  final Function() onCallBack;
  final String selectText;
  final String? hintText;
  final bool? isRequired;
  final bool isEnabled;
  final bool isShowDivider;
  final double? height;
  final FontWeight? titleFontWeight;

  @override
  State<CustomSelectPage> createState() => _CustomSelectPageState();
}

class _CustomSelectPageState extends State<CustomSelectPage> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          children: [
            Visibility(
                visible: widget.isRequired ?? true,
                child: Text(
                  '*',
                  style: TextStyle(
                    fontSize: 14.sp,
                    height: 1.2,
                    color: AppColors.meaning_color_danger,
                  ),
                )),
            Text(
              widget.title,
              style: TextStyle(
                fontSize: 14.sp,
                height: 1.2,
                color: AppColors.font_color_black,
                fontWeight:widget.titleFontWeight,
              ),
            ),
            AppGaps.hGap6,
            Expanded(
                child: Container(
                  constraints: BoxConstraints(
                    minHeight: widget.height!.w,
                  ),
              // height: widget.height!.w,
              alignment: Alignment.centerRight,
              child: widget.selectText.isNotEmpty
                  ? Text(
                textAlign: TextAlign.end,
                      widget.selectText,
                      style: TextStyle(
                        fontSize: 14.sp,
                        height: 1.2,
                        color: const Color(0xFF262F38),
                      ),
                    )
                  : Text(
                      widget.isEnabled ? widget.hintText ?? '请选择' : '暂无',
                      style: TextStyle(
                        fontSize: 14.sp,
                        height: 1.2,
                        color: AppColors.text_grey,
                      ),
                    ),
            )),
            Visibility(
                visible: widget.isEnabled,
                child: Row(
                  children: [
                    AppGaps.hGap6,
                    Icon(Icons.arrow_forward_ios, size: 14.sp, color: AppColors.text_grey)
                  ],
                ))
          ],
        ),
        Visibility(
            visible: widget.isShowDivider,
            child: Divider(
              height: 1.w,
              color: AppColors.bg_color_grey,
            )),
      ],
    ).clickOnce(() {
      FocusScope.of(context).unfocus();
      if (widget.isEnabled) {
        widget.onCallBack();
      }
    });
  }
}
